import { MockMethod } from "vite-plugin-mock";
import { resultError } from "../_utils";
import { token } from "../helper/_token";
import { ResponseData, TokenInfo } from "@scpun/core";

export function createFakeUserList() {
    return [
        {
            userId: "1",
            username: "super",
            realName: "超级管理员",
            avatar: "https://loremflickr.com/300/150?lock=1115",
            desc: "超级管理员",
            password: "123456",
            token: "fakeToken1",
            homePath: "/dashboard/analysis",
            roles: [
                {
                    roleName: "Super Admin",
                    value: "super",
                },
            ],
        },
    ];
}

export default [
    {
        url: "/mock-api/oauth2/token",
        method: "post",
        timeout: 1000,
        response: (params: { query: Recordable }) => {
            const { query } = params;
            let json: ResponseData<string> | TokenInfo = resultError(
                "Incorrect account or password！"
            ) as unknown as ResponseData<string>;
            if (query.username === "super" && query.password === "123456") {
                return token;
            }
            return json;
        },
    },
] as MockMethod[];
